<?php
/**
 * A representation of a resource record of type <b>PTR</b>
 *
 * @category   Net
 * @package    Net_DNS2
 * @subpackage Net_DNS2_RR
 * @author     Till Klampaeckel <till@php.net>
 * @version    Release: @package_version@
 * @link       http://code.google.com/net-dns2/
 */
class Net_DNS2_RR_PTR extends Net_DNS2_RR
{
    public $name;
    public $type;
    public $class;
    public $ttl;
    public $rdlength;
    public $rdata;
    public $ptrdname;

    public function __construct(&$rro, $data, $offset = '')
    {
        $this->name = $rro->name;
        $this->type = $rro->type;
        $this->class = $rro->class;
        $this->ttl = $rro->ttl;
        $this->rdlength = $rro->rdlength;
        $this->rdata = $rro->rdata;


        if ($offset) {
            if ($this->rdlength > 0) {
                list($ptrdname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
                $this->ptrdname = $ptrdname;
            }
        } else {
            $this->ptrdname = ereg_replace("[ \t]+(.+)[ \t]*$", '\\1', $data);
        }
    }

    public function rdatastr()
    {
        if (strlen($this->ptrdname)) {
            return $this->ptrdname . '.';
        }
        return '; no data';
    }

    public function rr_rdata($packet, $offset)
    {
        if (strlen($this->ptrdname)) {
            return $packet->dn_comp($this->ptrdname, $offset);
        }
        return null;
    }
}
?>